package testProject;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.onpositive.page.pagerendering.SiteContentRenderer;
import com.onpositive.page.pagerendering.interfaces.ISiteContentRenderer;
import com.onpositive.storage.managers.UnifiedContentProvider;

@SuppressWarnings("serial")
public class PagesShowServlet extends HttpServlet {

	private static ISiteContentRenderer iscr = SiteContentRenderer.getSiteContentRenderer();
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		HttpServletRequest hs = req;
		String localAddr = hs.getRequestURI();
		
		//InputStream is1 = getServletContext().getResourceAsStream(localAddr);
		//UnifiedContentProvider.storeContentElement(localAddr, new InputStreamReader(is1));
		InputStream is = UnifiedContentProvider.getContentElementAsStream(localAddr);

		iscr.initRenderer(getServletContext());
		iscr.render(resp, new InputStreamReader(is), localAddr,true);
	}
}
